<template>
  <div>
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <FilterTable
      ref="table"
      columnsRef="testindex"
      :isExportExcel2="true"
      exportFileName="备件发运单.xlsx"
      :columns="columns"
      :fetchapi="fetchApi"
      :isSelectColumn="false"
      :params="fetchParams"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectData"
    >
    </FilterTable>

    <Drawer
      :visible.sync="visibleDrawer"
      title="签收单明细"
      :width="920"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
       >
      <info-model v-model="initData" @close="infoClose" />
    </Drawer>

    <BaseDialog title="服务站查询" :visible.sync="isShowSearchCustomer" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <SearchCustomer :customerNo="kehuxuanze" @close="isShowSearchCustomer = false" @addCustomerCode="confirmSearchCustomer" />
    </BaseDialog>
  </div>
</template>

<script>
import { ddztArr } from './constant';
import SearchCustomer from './SearchCustomer';
import infoModel from './info';
import { dictionary } from '@/utils/dictMixin';
import { getShipmentData } from '@/api/partsmanage/shipmentoem/query';
export default {
  name: 'shipmentqueryindex',
  mixins: [dictionary],
  components: {
    infoModel,
    SearchCustomer
  },
  data() {
    return {
      topFilterList: this.createTopFilterList(),
      fetchParams: { xhrAbort: true },
      columns: this.createTableColumns(),
      fetchApi: getShipmentData,
      kehuxuanze: '',
      visibleDrawer: false,
      isShowSearchCustomer: false,
      issearch: false,
      dealerCode: '',
      initData: {}
    }
  },
  mounted() {
    // 分页
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '服务站代码',
          fieldName: 'dealerCode',
          readonly: true,
          unitRender: () => {
            return (
              <el-button
            icon="el-icon-search"
            onClick={() => {
              this.isShowSearchCustomer = true;
            }}
          ></el-button>
          );
          },
          onEnter: val => {
            console.log('对方经销商 onEnter');
            this.isShowSearchCustomer = true;
          }
        },
        {
          type: 'INPUT',
          label: '服务站名称:',
          fieldName: 'dealerName',
          maxlength: 30
        },
        {
          type: 'INPUT',
          label: '承运单号:',
          fieldName: 'coNo',
          maxlength: 30,
          change: val => this.handleInputChange(val,'coNo')
        },
        {
          type: 'INPUT',
          label: '交货单号',
          fieldName: 'bjxmbh',
          maxlength: 30,
          change: val => this.handleInputChange(val,'bjxmbh')
        },
        {
          type: 'SELECT',
          label: '签收状态:',
          fieldName: 'xsdjzt',
          placeholder: '请选择...',
          itemList: ddztArr
        },
        {
          type: 'RANGE_DATE',
          label: '发运日期',
          initialValue: '',
          fieldName: 'startTime|endTime',
          valueFormat: 'yyyy-MM-dd',
          placeholder: '请选择'
        },
        {
          type: 'RANGE_DATE',
          label: '签收日期',
          initialValue: '',
          fieldName: 'startDate|endDate',
          valueFormat: 'yyyy-MM-dd',
          placeholder: '请选择'
        },
        {
          type: 'RANGE_DATE',
          label: '到货日期',
          initialValue: '',
          fieldName: 'startTo|endTo',
          valueFormat: 'yyyy-MM-dd',
          placeholder: '请选择'
        },
        {
          type: 'INPUT',
          label: 'SAP订单号:',
          fieldName: 'SAP_NO',
          hidden:true
        },
        {
          type: 'INPUT',
          label: '发运单号:',
          fieldName: 'bsysdh',
          hidden:true
        },

        {
          type: 'INPUT',
          label: '配件代码:',
          fieldName: 'bjxmbh',
          hidden: true,
          hidden:true
        },
        {
          type: 'INPUT',
          label: '配件名称:',
          fieldName: 'bjzwmc',
          hidden: true
        },
      ]
    },
    createTableColumns() {
      return [

        {
          title: '操作',
          dataIndex: 'column-action',
          width: 50,
          render: (props, h) => {
            return (
              <div>
                <multiuse-button  size="mini" type="text" onClick={() => this.detailHandle(props.row, 'show')}>
                  明细
                </multiuse-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          fixed: 'left',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '签收状态',
          dataIndex: 'xsdjzt',
          sorter: true,
          dictItems: ddztArr
        },
        {
          title: '服务站代码',
          dataIndex: 'ownerCode',
          sorter: true,
        },
        {
          title: '服务站名称',
          dataIndex: 'sasa1',
          sorter: true,
          width: 200
        },
        {
          title: '厂家发货仓库名称',
          dataIndex: 'shipmentWarehouse',
          sorter: true,
          width: 200
        },
        {
          title: '承运单号',
          dataIndex: 'coNo',
          sorter: true,
        },
        {
          title: '采购单号',
          dataIndex: 'bscsdj',
          sorter: true,
          width: 180
        },
        {
          title: '交货单号',
          dataIndex: 'bsysdh',
          sorter: true,
          width: 180
        },
        {
          title: '发运方式',
          dataIndex: 'btyslx',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.btyslx, '3024')}</span>;
          }
        },
        {
          title: '发运日期',
          dataIndex: 'bsfyrq',
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
        },
        {
          title: '到货日期',
          dataIndex: 'bsscrq',
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          width: 180
        },
        {
          title: '签收日期',
          dataIndex: 'bsqcrq',
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          width: 180
        },
        {
          title: '预计到货日期',
          dataIndex: 'bsyjdd',
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
        },
        {
          title: '物流公司',
          dataIndex: 'wsName',
          sorter: true,
          hidden:true
        },

      {
        title: '承运状态',
        dataIndex: 'bsfysl',
        sorter: true,
        hidden:true
      },
      {
        title: '承运商名称',
        dataIndex: 'qssl',
        sorter: true,
        hidden:true
      },
      {
        title: '包装总件数', //待补充完善
        dataIndex: 'bsysdd',
        sorter: true,
        width: 180,
        hidden:true
      },
      {
        title: '运费',
        dataIndex: 'bssjsl',
        sorter: true,
        hidden:true
      },
      {
        title: '承运联系人',
        dataIndex: 'bszssl',
        sorter: true,
        hidden:true
      },
      {
        title: '联系电话',
          dataIndex: 'bszssl',
        sorter: true,
        hidden:true
      },
      {
        title: '收货地址',
          dataIndex: 'bszssl',
        sorter: true,
        hidden:true
      },
      {
        title: '备注',
        dataIndex: 'REMARK',
        sorter: true,
        hidden:true
      },
      ]
    },
    changeHandle(val) {
      // this.fetchParams = Object.assign({}, val);
      console.info(val)
      val.endTime && (val.endTime = val.endTime.split(' ')[0] + ' 23:59:59');
      this.fetchParams = Object.assign({},val);
      console.info(this.fetchParams)
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    selectData(val) {
      this.tableData = val;
    },
    detailHandle(row, type) {
      this.initData =  {
        type: type,
        data: row,
        id:1001
      }; //行id
      this.visibleDrawer = true;
    },
    infoClose(rData) {
      this.visibleDrawer = false;
      if (rData.type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    dealercloseHandler(val){
      console.info(val)
      if(val){
        this.topFilterList.find(x=>x.fieldName=='dealerCode').initialValue=val.dealerCode;
        this.fetchParams=Object.assign({
          dealerCode: val.dealerCode
        },this.fetchParams)
        this.dealerCode=val.dealerCode
        Object.assign({ dealerCode: this.dealerCode }, this.fetchParams)
      }
      this.issearch=false;
    },

    async confirmSearchCustomer(row) {
      this.rowData = row[0];
      this.topFilterList.find(x => x.fieldName == 'dealerCode').initialValue = row[0].dealerCode;
      this.topFilterList.find(x => x.fieldName == 'dealerName').initialValue = row[0].dealerName;
    },

    async handleInputChange(val,key){
      if (key === 'coNo'){
        var li= /[\u4e00-\u9fa5]/.test(val);
        if(li===true){
          this.topFilterList.find(x => x.fieldName === 'coNo').initialValue = '';
          return this.$message.warning('承运单号不要输入包含中文字符');
        }
      }
      if (key === 'bjxmbh'){
        var li= /[\u4e00-\u9fa5]/.test(val);
        if(li===true){
          this.topFilterList.find(x => x.fieldName === 'bjxmbh').initialValue = '';
          return this.$message.warning('交货单号不要输入包含中文字符');
        }
      }
    },
    seacherFun(){
      this.issearch=true;
    }
  }
}
</script>
